<?php
declare (strict_types = 1);

namespace app\home\controller;
use app\BaseController;
use think\Request;

use app\home\model\Tool;
use app\home\model\Tool_type;

class Home extends BaseController
{
    public function home()
    {
    	if(request()->isPost()){
            $toolModel     = new Tool();
            $toolTypeModel = new Tool_type();

            $toolTypeList = $toolTypeModel->getList();

            $field = 'id, tid, title, brief, is_show, is_download, download_url, link_url, icon_img';

            $toolData = '';
            foreach($toolTypeList as $k => $v){
            	$toolData .= '<div class="container cont-border" style="border-color:'. $v['color'] .'">
            		<div class="cont-title" style="background-color:'. $v['color'] .'">'. $v['name'] .'</div>
            		<div class="row cont-row">';

            	$toolList = $toolModel->getList(['tid' => $v['id']], $field);

            	foreach($toolList as $key => $val){
            		$toolData .= '<div class="col-2 col-md-3 card-padding">
				  		<div class="card">
				  			<div style="display: flex;">
				  				<img class="card-img" src="'. $val['icon_img'] .'">
							  	<div class="card-body" style="padding:0.7rem; margin: auto 0">
							    	<h6 class="card-title">'. $val['title'] .'</h6>
							    	<p class="text-font">'. $val['brief'] .'</p>
							  	</div>
				  			</div>
				  			<div>';

				  	if($val['is_download'] == 1){
				  		$toolData .= '<button type="button" class="btn btn-link card-btn">立即下载</button>';
				  	}
						  		
					$toolData .= '<a href="'. $val['link_url'] .'"><button type="button" class="btn btn-link card-btn">进入</button></a></div></div></div>';
            	}

            	$toolData .= '</div></div></div>';
            }

	        return backData($toolData, 200, '成功');
	    }

        return view();
    }

    public function time()
    {
        if(request()->isPost()){

        }

        return view();
    }
}
